//
//  WBVisitorView.m
//  WeiBoOC
//
//  Created by 韩菲菲 on 16/8/9.
//  Copyright © 2016年 韩菲菲. All rights reserved.
//

#import "WBVisitorView.h"
#import "Masonry.h"



@interface WBVisitorView ()

//显示转圈的图片
@property (nonatomic , strong) UIImageView *circleImageView;

//显示中间房子的图片
@property (nonatomic , strong) UIImageView *hostImageView;

//显示遮罩的图片
@property (nonatomic , strong) UIImageView *maskImageView;

//显示信息的label
@property (nonatomic , strong) UILabel *messageLabel;

//注册按钮
@property (nonatomic , strong) UIButton *registerBtn;

//登录按钮
@property (nonatomic , strong) UIButton *loginBtn;



@end

@implementation WBVisitorView

//懒加载控件
- (UIImageView *)circleImageView
{
    if (!_circleImageView) {
        //1 转圈的
        _circleImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_smallicon"]];
    }
    return _circleImageView;

}

- (UIImageView *)hostImageView
{
    if(!_hostImageView)
    {
        _hostImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_image_house"]];
    
    }
    
    return _hostImageView;


}

- (UIImageView *)maskImageView
{
    if(!_maskImageView)
    {
    
        _maskImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"visitordiscover_feed_mask_smallicon"]];
    
    }
    return _maskImageView;

}

- (UILabel *)messageLabel
{
    if(!_messageLabel)
    {
        _messageLabel = [[UILabel alloc] init];
        
        //设置文本字体
        _messageLabel.font = [UIFont systemFontOfSize:15];
        //设置文本颜色
        _messageLabel.textColor = AppColor;
        //设置文本最大显示宽度
        _messageLabel.preferredMaxLayoutWidth = 240;
        //设置换行
        _messageLabel.numberOfLines = 0;
        //设置文字
        _messageLabel.text = @"关注一些人，回这里看看有什么惊喜关注一些人，回这里看看有什么惊喜";
    
    }
    return _messageLabel;
}

- (UIButton *)registerBtn
{
    
    if(!_registerBtn)
    {
        
        //创建按钮
        _registerBtn = [[UIButton alloc] init];
        //添加按钮点击事件
        [_registerBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        //设置背景图片
        [_registerBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        //设置文字
        [_registerBtn setTitle:@"注册" forState:UIControlStateNormal];
        //设置文字大小
        _registerBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        //设置文字颜色
        [_registerBtn setTitleColor:AppColor forState:UIControlStateNormal];
    
    }
    
    
    return _registerBtn;

}

- (UIButton *)loginBtn
{
    if(!_loginBtn)
    {
        //创建按钮
        _loginBtn = [[UIButton alloc] init];
        //添加按钮点击事件
        [_loginBtn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
        //设置背景图片
        [_loginBtn setBackgroundImage:[UIImage imageNamed:@"common_button_white_disable"] forState:UIControlStateNormal];
        //设置文字
        [_loginBtn setTitle:@"登录" forState:UIControlStateNormal];
        //设置文字大小
        _loginBtn.titleLabel.font = [UIFont systemFontOfSize:15];
        //设置文字颜色
        [_loginBtn setTitleColor:AppColor forState:UIControlStateNormal];
    
    
    }
    
    
    return _loginBtn;



}

- (void)btnClick
{
    
    if(self.modalBlock)
    {
    
        self.modalBlock();
    
    }


}


- (void)viewWithLableText:(NSString *)text andImageViewName:(NSString *)imageName
{
    if(text == nil || imageName == nil)
    {
        //首页 图片旋转
        [self imageRotation];
        
    }else
    {
        //设置文本
        self.messageLabel.text = text;
        
        //设置图片
        self.hostImageView.image = [UIImage imageNamed:imageName];
        
        //旋转图片隐藏
        self.circleImageView.hidden = YES;
        
        
    }
 
}

- (void)imageRotation
{
    //创建基本动画
    CABasicAnimation *anim = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    //设置属性变化
    anim.toValue =@(M_PI * 2);
    //设置动画时间
    anim.duration = 10;
    //设置动画中执行次数
    anim.repeatCount = MAXFLOAT;
    //设置切换子控制器动画不移除
    anim.removedOnCompletion = NO;
    //给控件添加动画
    [self.circleImageView.layer addAnimation:anim forKey:nil];
}


//只要创建这个控件就会调用这个方法[alloc init]
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
     self.backgroundColor = [UIColor colorWithRed:237/255.0 green:237/255.0 blue:237/255.0 alpha:1];
    
    [self setupUI];
    
    return self;
}

//创建控件，以及设置约束
- (void)setupUI
{
    //添加转圈图片
    [self addSubview:self.circleImageView];
    //设置约束
    [self.circleImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        //图片的中心和self.view视图中心一样
        make.center.equalTo(self);
    }];
    
    //2 遮罩
    [self addSubview:self.maskImageView];
    [self.maskImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    //3 小房子
    //添加
    [self addSubview:self.hostImageView];
    //设置约束
    [self.hostImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
    }];
    
    //4 显示文本信息的Label
   
    //添加到父控件
    [self addSubview:self.messageLabel];
    //设置约束
    [self.messageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.maskImageView.mas_bottom).mas_offset(16);
        make.centerX.equalTo(self.mas_centerX);
        make.height.mas_equalTo(36);
    }];
    
    //5 添加注册按钮
    
    //添加到父控件
    [self addSubview:self.registerBtn];
    
    //设置约束
    [self.registerBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.messageLabel);
        make.size.mas_equalTo(CGSizeMake(100, 36));
        make.top.mas_equalTo(self.messageLabel.mas_bottom).mas_offset(16);
    }];
    
    //6 添加登录按钮
    
    //添加到父控件
    [self addSubview:self.loginBtn];
    
    //设置约束
    [self.loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.top.mas_equalTo(self.registerBtn);
        make.trailing.mas_equalTo(self.messageLabel);
    }];
    
}


@end
